package com.example.demoofviewapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.example.demoofviewapp.pie.PieButtonLayout;
import com.example.demoofviewapp.pie.bean.PieItem;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        super.onResume();

        LinearLayout layout = (LinearLayout) findViewById(R.id.main_layout);
        PieButtonLayout pieButtonLayout = new PieButtonLayout(this);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        pieButtonLayout.setCenter(dm.widthPixels / 2, dm.heightPixels / 2);
        pieButtonLayout.setLayoutParams(lp);

        pieButtonLayout.addItem(pieButtonLayout.makeItem("1"));
        pieButtonLayout.addItem(pieButtonLayout.makeItem("2"));
        pieButtonLayout.addItem(pieButtonLayout.makeItem("3"));

        pieButtonLayout.setOnItemClickListener(new PieButtonLayout.OnItemClickListener() {

            @Override
            public void onItemClick(PieItem item) {
                Toast.makeText(MainActivity.this, "item click" + item, Toast.LENGTH_SHORT).show();
            }
        });

        layout.addView(pieButtonLayout);
    }
}